<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>


    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="/bower_components/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="/bower_components/Ionicons/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="/dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="/dist/css/skins/_all-skins.min.css">


</head>
<body>


<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper" style="margin-left: 0;">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            Simple Tables
            <small>preview of simple tables</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">Tables</a></li>
            <li class="active">Simple</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box">
                    <div class="box-header with-border">
                        <h3 class="box-title">ajax 下拉联动</h3>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body">


                       <select id="area" >
                           <option value="">这是第一项</option>

                           <option value="">这是第二项</option>
                       </select>

                        <select id="city" >
                            <option value="">这是第一city</option>

                            <option value="">这是第二city</option>
                        </select>





                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer clearfix">

                    </div>
                </div>
                <!-- /.box -->

            </div>
            <!-- /.col -->

        </div>

    </section>
    <!-- /.content -->
</div>


<!-- jQuery 3 -->
<script src="/bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- Slimscroll -->
<script src="/bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="/bower_components/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="/dist/js/adminlte.min.js"></script>

<script type="application/javascript">


    $(function () {



        $.ajax({
            method: "POST",
            url: "/webapi/area/findbyparentid",
            data: { parentid: 0 }
        })
            .done(function( result ) {

                var len=result.length;

                var html="<option>--请选择---</option>"
                for(var i=0;i<len;i++){
                    html+= ' <option value="'+result[i].id+'">'+
                        result[i].areaName
                        +'</option>';


                }

                $("#area").html(html)


                $("#area").change(function () {
                    // alert($(this).val())

                    var value=$(this).val();


                    $.ajax({
                        method: "POST",
                        url: "/webapi/area/findbyparentid",
                        data: { parentid:value }
                    })
                        .done(function( result2 ) {


                            var len=result2.length;

                            var html="<option>--请选择---</option>"
                            for(var i=0;i<len;i++){
                                html+= ' <option value="'+result2[i].id+'">'+
                                    result2[i].areaName
                                    +'</option>';


                            }


                            $("#city").html(html)

                        });//end of parentid = area code



                    
                })

            });//end of done for parentid=0


        
    })



</script>

</body>
</html>